package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.ApiParam;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

/**
 * 护理等级Controller类
 */
@RestController
@RequestMapping("nursingLevel")
public class NursingLevelController {
  @Autowired
  private NursingLevelService nursingLevelService;

  @GetMapping("listAll")
  public ResponseResult listAll() {
    NursingLevelVo nursingLevelVo = nursingLevelService.listAll();
    return ResponseResult.success(nursingLevelVo);
  }

  @PostMapping("insert")
  public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto) {
    nursingLevelService.add(nursingLevelDto);
    return success();
  }

  @GetMapping("listByPage")
  public ResponseResult<PageResponse<NursingLevelVo>> getList(
          @ApiParam(value = "当前页码")
          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
          @ApiParam(value = "每页显示数量")
          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
          @ApiParam(value = "护理等级名称")
          @RequestParam(value = "name", required = false) String name,
          @ApiParam(value = "护理等级状态：0-禁用，1-启用")
          @RequestParam(value = "status", required = false) Integer status) {
    PageResponse<NursingLevelVo> levelVoPageResponse = nursingLevelService.getList(pageNum, pageSize, name, status);
    return ResponseResult.success(levelVoPageResponse);
  }

  @GetMapping("{id}")
  public ResponseResult getById(@PathVariable("id") String id) {
    NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
    return success(nursingLevelVo);
  }


  @PutMapping("update")
  public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto) {
    nursingLevelService.update(nursingLevelDto);
    return success();
  }

  @DeleteMapping("delete/{id}")
  public ResponseResult deleteByID(@PathVariable("id") String id) {
    nursingLevelService.deleteById(id);
    return success();
  }

  @PutMapping("{id}/status/{status}")
  public ResponseResult isActive(@PathVariable("id") String id, @PathVariable("status") Integer status) {
    nursingLevelService.isActive(id, status);
    return success();
  }
}
